package com.yangzb;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        // 配置HBase
        Configuration config = HBaseConfiguration.create();
        config.set("hbase.zookeeper.quorum", "your_zookeeper_quorum");

        // 建立连接
        Connection connection = ConnectionFactory.createConnection(config);

        // 表名
        TableName tableName = TableName.valueOf("your_table_name");

        // 创建HTable实例
        HTable table = new HTable(config, tableName);

        // 准备批量写入的数据
        List<Put> puts = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Put put = new Put(Bytes.toBytes("row" + i));
            put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual"), Bytes.toBytes("value"));
            puts.add(put);
        }

        // 执行批量写入
        table.put(puts);

        // 关闭连接
        table.close();
        connection.close();
    }
}
